#include <stdio.h>

#include <octopus.h>
#include "eeprom.h"
#include "test.h"
#include "random.h"

int _check_eeprom(int length)
{
  char buf[120];
  char write[120];
  char read[120];
  int addr;
  int i;

  test_start("EEPROM");

  for(i = 0; i < 120; i++)
  {
    write[i] = 0;
    read[i]  = 0;
  }
  
  random_string(write, length);
  addr = random_number(30,300);

  octopus_eeprom_write_bytes(&octopus, addr, write, length);
  octopus_eeprom_read_bytes(&octopus,  addr, read,  length);


  for(i = 0; i < length; i++)
  {
    if(write[i] != read[i])
    {
      sprintf(buf, "addr: %d\n\twrite: >%s<\n\tread: >%s<\n\n", addr, write, read);
      test_failed(buf);
      return -1;
    }
  }

  test_ok();
  return 1;
}

void check_eeprom()
{
  int i;
  for(i = 10; i <= 100; i += 10)
  _check_eeprom(1);
}
